{template "nheader.html"}
<script type="text/javascript">
    $(function () {
        // 错误提示
        {
            if $error}
        dr_tips('{$error.msg}', 3, '{intval($error.status)}');
        {
            /if}
            // 生成静态文件
            {
                if $create}
            $.ajax({
                type: "GET",
                async: false,
                url: "{$create}",
                dataType: "jsonp",
                success: function (json) {
                },
                error: function () {
                }
            });
            $.ajax({
                type: "GET",
                async: false,
                url: "index.php?s={APP_DIR}&c=home&m=create_list_html&id={$catid}",
                dataType: "jsonp",
                success: function (json) {
                },
                error: function () {
                }
            });
            {
                /if}
                //每隔5秒保存表单数据
                {
                    if !$data.id && !$did}
                setInterval("dr_save_add_data()", 5000);
                {
                    /if}
                    // 加载草稿
                    $("#dr_cgbox").mouseover(function () {
                        $(".dr_cgbox").show();
                    }).mouseout(function () {
                        $(".dr_cgbox").hide();
                    });
                    $(".dr_cgbox_select").click(function () {
                        var did = $(this).attr("did");
                        var islock = $(this).attr("islock");
                        if (did != undefined && islock == "0") {
                            window.location.href = '{$draft_url}&did=' + did;
                        }

                    });
                    // 自动保存草稿
                    {
                        if $did}
                    setInterval("dr_save_draft_data()", 5000);
                    {
                        /if}
                        //
                        {
                            if $data.syncatid}
                        $("#dr_syncat_num").html("{php echo substr_count($data.syncatid, '|')}");
                        $("#dr_syncat_text").show();
                        {
                            /if}
                        }
                    );

    // 修改栏目时的页面跳转
    function show_category_field(catid) {
        {
            if $is_category_field}
        window.location.href = '{dr_url(APP_DIR."/home/".$ci->router->method, array("id"=>$data.id))}&catid=' + catid;
        {
            /if}
        }

// 动态保存草稿数据
        function dr_save_draft_data() {
            var catid = $('#dr_catid').val();
            $.ajax({
                type: "POST",
                dataType: "json",
                url: memberpath + 'index.php?s=member&c=api&m=ajax_save_draft&sid={SITE_ID}&dir={APP_DIR}&did={$did}&catid=' + catid,
                data: $("#myform").serialize(),
                success: function (data) {
                },
                error: function (HttpRequest, ajaxOptions, thrownError) {
                }
            });
        }

// 动态保存表单数据
        function dr_save_add_data() {
            $.ajax({
                type: "POST",
                dataType: "json",
                url: memberpath + 'index.php?s=member&c=api&m=ajax_save_add&dir={APP_DIR}',
                data: $("#myform").serialize(),
                success: function (data) {
                },
                error: function (HttpRequest, ajaxOptions, thrownError) {
                }
            });
        }

// 同步到其他栏目选择
        function dr_syncat() {
            var url = "{dr_url(APP_DIR.'/home/syncat_ajax')}&ids=" + $("#dr_syncatid").val();
            art.dialog.open(url, {
                title: '{lang("cat-100")}',
                ok: function () {
                    var iframe = this.iframe.contentWindow;
                    if (!iframe.document.body) {
                        alert('iframe loading')
                        return false;
                    }
                    ;
                    var c = 0;
                    var v = '';
                    iframe.$("input[type='hidden']").each(function (i) {
                        v += $(this).val() + '|';
                        c++;
                    });
                    $("#dr_syncatid").val(v);
                    $("#dr_syncat_num").html(c);
                    $("#dr_syncat_text").show();
                    return true;
                },
                cancel: true
            });
        }

// 删除草稿数据
        function delete_draft(did) {
            $("#dr_row_cgbox_" + did).attr("islock", 1);
            var num = parseInt($("#dr_cg_nums").html());
            $.ajax({
                type: "POST",
                dataType: "json",
                url: memberpath + 'index.php?s=member&c=api&m=ajax_delete_draft&sid={SITE_ID}&dir={APP_DIR}&did=' + did,
                success: function (data) {
                    $("#dr_cgbox_" + did).attr("islock", 0);
                    if (data == did) {
                        $("#dr_cgbox_" + did).remove();
                        $("#dr_cg_nums").html(num - 1);
                    } else {
                        dr_tips(data);
                    }
                },
                error: function (HttpRequest, ajaxOptions, thrownError) {
                }
            });
        }
</script>
<form class="form-horizontal" action="" method="post" id="myform" name="myform">
	<input name="page" id="page" type="hidden" value="{$page}"/>
	<input name="action" id="dr_action" type="hidden" value="back"/>
	<input name="dr_id" id="dr_id" type="hidden" value="{$data.id}"/>
	<input name="dr_module" id="dr_module" type="hidden" value="{APP_DIR}"/>
	<div class="page-bar">
		<ul class="page-breadcrumb mylink">
			{$menu.link}
		</ul>
		<ul class="page-breadcrumb myname">
			{$menu.name}
		</ul>
		<div class="page-toolbar">
			<div class="btn-group pull-right">
				<button type="button" class="btn green btn-sm btn-outline dropdown-toggle" data-toggle="dropdown"
				        aria-expanded="false" data-hover="dropdown"> {fc_lang('操作菜单')}
					<i class="fa fa-angle-down"></i>
				</button>
				<ul class="dropdown-menu pull-right" role="menu">
					{loop $menu.quick $t}
					<li>
						<a href="{$t.url}">{$t.icon} {$t.name}</a>
					</li>
					{/loop}
					<li class="divider"></li>
					<li>
						<a href="javascript:window.location.reload();">
							<i class="icon-refresh"></i> {fc_lang('刷新页面')}</a>
					</li>
				</ul>
			</div>
		</div>
	</div>
	
	<div class="row" style="margin-top:20px;margin-bottom: 50px;">
		<div class="col-md-9">
			<div class="portlet light bordered">
				<div class="portlet-title">
					<div class="caption">
						<span class="caption-subject font-green sbold uppercase">{fc_lang('基本内容')}</span>
					</div>
					{if $draft_list}
					<div class="actions">
						<div class="btn-group">
							<a class="btn green-haze btn-outline btn-circle btn-sm" href="javascript:;"
							   data-toggle="dropdown" data-hover="dropdown" data-close-others="true"> <i
									class="fa fa-edit"></i> {fc_lang('草稿')} <span class="badge badge-success"
							                                                      id="dr_cg_nums">{count($draft_list)}</span>
								<i class="fa fa-angle-down"></i>
							</a>
							<ul class="dropdown-menu pull-right" style="width:320px">
								{loop $draft_list $t}
								<li id="dr_cgbox_{$t.id}">
									<a href="javascript:;" class="dr_cgbox_select" id="dr_row_cgbox_{$t.id}"
									   did="{$t.id}" islock="0">{if $t.title}{$t.title}{else}---{/if} <span
											class="badge badge-s-danger" onclick="delete_draft('{$t.id}')"> <i
											class="fa fa-trash"></i> {dr_date($t.inputtime)}</span></a>
								</li>
								{/loop}
							</ul>
						</div>
					</div>
					{/if}
				</div>
				<div class="portlet-body">
					<div class="form-body">
						<div class="form-group">
							<label class="col-md-2 control-label">{fc_lang('栏目分类')}：</label>
							<div class="col-md-9">
								<label>{$select}</label>
								{if $ci->get_cache('module-'.SITE_ID.'-'.APP_DIR, 'setting', 'syncat')}
								{if !$data.id}
								<label><a href="javascript:;" onclick="dr_syncat()">[{fc_lang('同步发布到其他栏目')}]</a></label>
								<label>
									<input name="syncatid" id="dr_syncatid" type="hidden" value="{$data.syncatid}"/>
									<span id="dr_syncat_text" style="display: none;color: blue;">{fc_lang('已选择：')}<b
											id="dr_syncat_num">0</b></span>
								</label>
								{else if $data.link_id != 0}
								<label>{fc_lang('修改内容时会同步更新其他外联文档')}</label>
								{/if}
								{/if}
							</div>
						</div>
						{str_replace('col-md-9', 'col-md-10', $myfield)}
					</div>
				</div>
			</div>
			
			{if $flag || (!$data.id && $ci->get_cache('module-'.SITE_ID.'-'.APP_DIR, 'setting', 'syn2'))}
			<div class="portlet light bordered" style="display: none;">
				<div class="portlet-title">
					<div class="caption">
						<span class="caption-subject font-green sbold uppercase">{fc_lang('更多设置')}</span>
					</div>
				</div>
				<div class="portlet-body">
					<div class="form-body">
						{if $flag}
						<div class="form-group">
							<label class="col-md-2 control-label">{fc_lang('推荐位')}：</label>
							<div class="col-md-9">
								<div class="checkbox-list">
									{loop $flag $i $t}
									{if $t.name}
									<label class="checkbox-inline"><input name="flag[]" type="checkbox" {if
									                                      @in_array($i, $myflag)}checked="checked" {/if}value="{$i}"
										/> {$t.name} </label>
									{/if}
									{/loop}
								</div>
							</div>
						</div>
						{/if}
						{if $ci->get_cache('module-'.SITE_ID.'-'.APP_DIR, 'setting', 'syn2')}
						<div class="form-group">
							<label class="col-md-2 control-label">{fc_lang('同步微博')}：</label>
							<div class="col-md-9">
								<label><input type="checkbox" name="sina_share" value="1" {if
								              !$data.id}checked="checked" {/if} data-on-text="{fc_lang('开启')}"
									data-off-text="{fc_lang('关闭')}" data-on-color="success" data-off-color="danger"
									class="make-switch" data-size="small"> </label>
							</div>
						</div>
						{/if}
					</div>
				</div>
			</div>
			{/if}
		</div>
		<div class="col-md-3">
			<div class="portlet light bordered">
				<div class="portlet-body">
					<div class="form-body">
						{$sysfield}
					</div>
				</div>
			</div>
		</div>
	</div>
	
	<div class="myfooter">
		<div class="row">
			<div class="portlet-body form">
				<div class="form-body">
					<div class="form-actions">
						<div class="row">
							<div class="col-md-12 text-center">
								<button type="submit" class="btn blue" onclick="$('#dr_action').val('draft')"><i
										class="fa fa-save"></i> {fc_lang('保存草稿')}
								</button>
								<button type="submit" class="btn green" onclick="$('#dr_action').val('back')"><i
										class="fa fa-save"></i> {fc_lang('保存并返回')}
								</button>
								{if !$data.id}
								<button type="submit" class="btn default" onclick="$('#dr_action').val('continue')"><i
										class="fa fa-save"></i> {fc_lang('保存并继续')}
								</button>
								{/if}
								<!--dayrui.com 测试有bug<label><button type="button" class="btn red" name="option" onClick="$('#action').val('timing');"> <i class="fa fa-save"></i> {fc_lang('定时发布')}</button></label>-->
							
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</form>
<style type="text/css">
	#dr_pic_tips {
		color: red;
	}
</style>
<script type="text/javascript">
    if ({$catid} == 17 || {$catid} == 18) {
        $('#dr_row_thumb').hide();
        $('#dr_row_keywords').hide();
        $('#dr_row_description').hide();
        $('#dr_row_content').hide();
    } else {
        $('#dr_row_nr').hide();
    }
    if ("{APP_DIR}" == "tp" || "{APP_DIR}" == "zp") {
        $('#dr_row_thumb').hide();
    }

</script>
{template footer.html}